/*
 * CreateEditSupplierDialog.java
 * 
 * Created: Aug 4, 2015
 * 
 * Copyright (c) ExpertPB 2015
 * All information contained herein is, and remains the property of
 * ExpertPB and its suppliers, if any.
 */
package com.emex.app.stuff.supplier;

import com.emex.app.shared.data.Cost;
import com.emex.app.shared.data.JuridicalPerson;
import com.emex.app.shared.data.Repayment;
import com.emex.app.shared.data.Supplier;
import com.emex.app.shared.data.SupplierMoney;
import com.emex.app.stuff.constant.IdentifierConstants;
import com.emex.app.stuff.juridic.SearchJuridicPersonDialog;
import com.emex.app.stuff.provider.CostDataProvider;
import com.emex.app.stuff.provider.JuridicalPersonDataProvider;
import com.emex.app.stuff.provider.SupplierDataProvider;
import com.emex.app.stuff.security.SecurityManager;
import com.emex.app.stuff.utils.UIUtils;
import java.util.ArrayList;
import java.util.List;
import org.openide.windows.WindowManager;

/**
 *
 * @author Sergey
 */
public class CreateEditSupplierDialog extends javax.swing.JDialog {

    private JuridicalPerson client;

    private Supplier supplier;
    private SupplierTableModel supplierTableModel;
    private List<SupplierMoney> moneyForSupplier;
    private List<SupplierMoney> paymentByClients;
    private List<SupplierMoney> paymentsByShop;
    private List<Repayment> returnedPayments;
    private SupplierMoneyTableModel moneyForSupplierTableModel;
    private SupplierMoneyTableModel paymentsByClientsTableModel;
    private SupplierMoneyTableModel paymentsByShopTableModel;
    private RepaymentTableModel returnedPaymentsTableModel;

    /**
     * Creates new form CreateEditSupplierDialog
     */
    public CreateEditSupplierDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        if (!SecurityManager.getDefault().getCurrentPerson().getIsAdmin()) {
            editPayment.setVisible(false);
            editPaymentByShop.setVisible(false);
            editPaymentForSupplier.setVisible(false);
            editReturn.setVisible(false);
            deletePayment.setVisible(false);
            deletePaymentByShop.setVisible(false);
            deletePaymentForSupplier.setVisible(false);
            deleteReturn.setVisible(false);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        providerNameTextField = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jurPersonField = new javax.swing.JTextField();
        loadIPButton1 = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        paymentForSupplier = new javax.swing.JPanel();
        controlsBar1 = new javax.swing.JToolBar();
        addPaymentForSupplier = new javax.swing.JButton();
        editPaymentForSupplier = new javax.swing.JButton();
        deletePaymentForSupplier = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        paymentsForSupplierTable = new org.jdesktop.swingx.JXTable();
        paymentsByShopPanel = new javax.swing.JPanel();
        controlsBar2 = new javax.swing.JToolBar();
        addPaymentByShop = new javax.swing.JButton();
        editPaymentByShop = new javax.swing.JButton();
        deletePaymentByShop = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        paymentsByShopTable = new org.jdesktop.swingx.JXTable();
        paymentPanel = new javax.swing.JPanel();
        controlsBar = new javax.swing.JToolBar();
        addPayment = new javax.swing.JButton();
        editPayment = new javax.swing.JButton();
        deletePayment = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        paymentsByClientsTable = new org.jdesktop.swingx.JXTable();
        returnsPanel = new javax.swing.JPanel();
        controlsBar3 = new javax.swing.JToolBar();
        addReturn = new javax.swing.JButton();
        editReturn = new javax.swing.JButton();
        deleteReturn = new javax.swing.JButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        returnedPaymentsTable = new org.jdesktop.swingx.JXTable();
        jLabel3 = new javax.swing.JLabel();
        balanceField = new javax.swing.JTextField();
        saveButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.title")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.jLabel1.text")); // NOI18N

        providerNameTextField.setText(org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.providerNameTextField.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.jLabel4.text")); // NOI18N

        jurPersonField.setText(org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.jurPersonField.text")); // NOI18N

        loadIPButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/view.png"))); // NOI18N
        org.openide.awt.Mnemonics.setLocalizedText(loadIPButton1, org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.loadIPButton1.text")); // NOI18N
        loadIPButton1.setToolTipText(org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.loadIPButton1.toolTipText")); // NOI18N
        loadIPButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loadIPButton1ActionPerformed(evt);
            }
        });

        controlsBar1.setFloatable(false);
        controlsBar1.setRollover(true);

        addPaymentForSupplier.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/add.png"))); // NOI18N
        org.openide.awt.Mnemonics.setLocalizedText(addPaymentForSupplier, org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.addPaymentForSupplier.text")); // NOI18N
        addPaymentForSupplier.setToolTipText(org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.addPaymentForSupplier.toolTipText")); // NOI18N
        addPaymentForSupplier.setFocusable(false);
        addPaymentForSupplier.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        addPaymentForSupplier.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        addPaymentForSupplier.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addPaymentForSupplierActionPerformed(evt);
            }
        });
        controlsBar1.add(addPaymentForSupplier);

        editPaymentForSupplier.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/edit.png"))); // NOI18N
        org.openide.awt.Mnemonics.setLocalizedText(editPaymentForSupplier, org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.editPaymentForSupplier.text")); // NOI18N
        editPaymentForSupplier.setToolTipText(org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.editPaymentForSupplier.toolTipText")); // NOI18N
        editPaymentForSupplier.setFocusable(false);
        editPaymentForSupplier.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        editPaymentForSupplier.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        editPaymentForSupplier.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editPaymentForSupplierActionPerformed(evt);
            }
        });
        controlsBar1.add(editPaymentForSupplier);

        deletePaymentForSupplier.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/delete.png"))); // NOI18N
        org.openide.awt.Mnemonics.setLocalizedText(deletePaymentForSupplier, org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.deletePaymentForSupplier.text")); // NOI18N
        deletePaymentForSupplier.setToolTipText(org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.deletePaymentForSupplier.toolTipText")); // NOI18N
        deletePaymentForSupplier.setFocusable(false);
        deletePaymentForSupplier.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        deletePaymentForSupplier.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        deletePaymentForSupplier.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deletePaymentForSupplierActionPerformed(evt);
            }
        });
        controlsBar1.add(deletePaymentForSupplier);

        jScrollPane2.setViewportView(paymentsForSupplierTable);

        javax.swing.GroupLayout paymentForSupplierLayout = new javax.swing.GroupLayout(paymentForSupplier);
        paymentForSupplier.setLayout(paymentForSupplierLayout);
        paymentForSupplierLayout.setHorizontalGroup(
            paymentForSupplierLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(paymentForSupplierLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(paymentForSupplierLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(controlsBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 585, Short.MAX_VALUE)
                    .addComponent(jScrollPane2))
                .addContainerGap())
        );
        paymentForSupplierLayout.setVerticalGroup(
            paymentForSupplierLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(paymentForSupplierLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(controlsBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab(org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.paymentForSupplier.TabConstraints.tabTitle"), paymentForSupplier); // NOI18N

        controlsBar2.setFloatable(false);
        controlsBar2.setRollover(true);

        addPaymentByShop.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/add.png"))); // NOI18N
        org.openide.awt.Mnemonics.setLocalizedText(addPaymentByShop, org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.addPaymentByShop.text")); // NOI18N
        addPaymentByShop.setToolTipText(org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.addPaymentByShop.toolTipText")); // NOI18N
        addPaymentByShop.setFocusable(false);
        addPaymentByShop.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        addPaymentByShop.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        addPaymentByShop.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addPaymentByShopActionPerformed(evt);
            }
        });
        controlsBar2.add(addPaymentByShop);

        editPaymentByShop.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/edit.png"))); // NOI18N
        org.openide.awt.Mnemonics.setLocalizedText(editPaymentByShop, org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.editPaymentByShop.text")); // NOI18N
        editPaymentByShop.setToolTipText(org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.editPaymentByShop.toolTipText")); // NOI18N
        editPaymentByShop.setFocusable(false);
        editPaymentByShop.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        editPaymentByShop.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        editPaymentByShop.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editPaymentByShopActionPerformed(evt);
            }
        });
        controlsBar2.add(editPaymentByShop);

        deletePaymentByShop.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/delete.png"))); // NOI18N
        org.openide.awt.Mnemonics.setLocalizedText(deletePaymentByShop, org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.deletePaymentByShop.text")); // NOI18N
        deletePaymentByShop.setToolTipText(org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.deletePaymentByShop.toolTipText")); // NOI18N
        deletePaymentByShop.setFocusable(false);
        deletePaymentByShop.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        deletePaymentByShop.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        deletePaymentByShop.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deletePaymentByShopActionPerformed(evt);
            }
        });
        controlsBar2.add(deletePaymentByShop);

        jScrollPane3.setViewportView(paymentsByShopTable);

        javax.swing.GroupLayout paymentsByShopPanelLayout = new javax.swing.GroupLayout(paymentsByShopPanel);
        paymentsByShopPanel.setLayout(paymentsByShopPanelLayout);
        paymentsByShopPanelLayout.setHorizontalGroup(
            paymentsByShopPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(paymentsByShopPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(paymentsByShopPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(controlsBar2, javax.swing.GroupLayout.DEFAULT_SIZE, 585, Short.MAX_VALUE)
                    .addComponent(jScrollPane3))
                .addContainerGap())
        );
        paymentsByShopPanelLayout.setVerticalGroup(
            paymentsByShopPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(paymentsByShopPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(controlsBar2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab(org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.paymentsByShopPanel.TabConstraints.tabTitle"), paymentsByShopPanel); // NOI18N

        controlsBar.setFloatable(false);
        controlsBar.setRollover(true);

        addPayment.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/add.png"))); // NOI18N
        org.openide.awt.Mnemonics.setLocalizedText(addPayment, org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.addPayment.text")); // NOI18N
        addPayment.setToolTipText(org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.addPayment.toolTipText")); // NOI18N
        addPayment.setFocusable(false);
        addPayment.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        addPayment.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        addPayment.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addPaymentActionPerformed(evt);
            }
        });
        controlsBar.add(addPayment);

        editPayment.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/edit.png"))); // NOI18N
        org.openide.awt.Mnemonics.setLocalizedText(editPayment, org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.editPayment.text")); // NOI18N
        editPayment.setToolTipText(org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.editPayment.toolTipText")); // NOI18N
        editPayment.setFocusable(false);
        editPayment.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        editPayment.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        editPayment.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editPaymentActionPerformed(evt);
            }
        });
        controlsBar.add(editPayment);

        deletePayment.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/delete.png"))); // NOI18N
        org.openide.awt.Mnemonics.setLocalizedText(deletePayment, org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.deletePayment.text")); // NOI18N
        deletePayment.setToolTipText(org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.deletePayment.toolTipText")); // NOI18N
        deletePayment.setFocusable(false);
        deletePayment.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        deletePayment.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        deletePayment.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deletePaymentActionPerformed(evt);
            }
        });
        controlsBar.add(deletePayment);

        jScrollPane1.setViewportView(paymentsByClientsTable);

        javax.swing.GroupLayout paymentPanelLayout = new javax.swing.GroupLayout(paymentPanel);
        paymentPanel.setLayout(paymentPanelLayout);
        paymentPanelLayout.setHorizontalGroup(
            paymentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(paymentPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(paymentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(controlsBar, javax.swing.GroupLayout.DEFAULT_SIZE, 585, Short.MAX_VALUE)
                    .addComponent(jScrollPane1))
                .addContainerGap())
        );
        paymentPanelLayout.setVerticalGroup(
            paymentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(paymentPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(controlsBar, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab(org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.paymentPanel.TabConstraints.tabTitle"), paymentPanel); // NOI18N

        controlsBar3.setFloatable(false);
        controlsBar3.setRollover(true);

        addReturn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/add.png"))); // NOI18N
        org.openide.awt.Mnemonics.setLocalizedText(addReturn, org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.addReturn.text")); // NOI18N
        addReturn.setToolTipText(org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.addReturn.toolTipText")); // NOI18N
        addReturn.setFocusable(false);
        addReturn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        addReturn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        addReturn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addReturnActionPerformed(evt);
            }
        });
        controlsBar3.add(addReturn);

        editReturn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/edit.png"))); // NOI18N
        org.openide.awt.Mnemonics.setLocalizedText(editReturn, org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.editReturn.text")); // NOI18N
        editReturn.setToolTipText(org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.editReturn.toolTipText")); // NOI18N
        editReturn.setFocusable(false);
        editReturn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        editReturn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        editReturn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editReturnActionPerformed(evt);
            }
        });
        controlsBar3.add(editReturn);

        deleteReturn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/delete.png"))); // NOI18N
        org.openide.awt.Mnemonics.setLocalizedText(deleteReturn, org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.deleteReturn.text")); // NOI18N
        deleteReturn.setToolTipText(org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.deleteReturn.toolTipText")); // NOI18N
        deleteReturn.setFocusable(false);
        deleteReturn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        deleteReturn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        deleteReturn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteReturnActionPerformed(evt);
            }
        });
        controlsBar3.add(deleteReturn);

        jScrollPane4.setViewportView(returnedPaymentsTable);

        javax.swing.GroupLayout returnsPanelLayout = new javax.swing.GroupLayout(returnsPanel);
        returnsPanel.setLayout(returnsPanelLayout);
        returnsPanelLayout.setHorizontalGroup(
            returnsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(returnsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(returnsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(controlsBar3, javax.swing.GroupLayout.DEFAULT_SIZE, 585, Short.MAX_VALUE)
                    .addComponent(jScrollPane4))
                .addContainerGap())
        );
        returnsPanelLayout.setVerticalGroup(
            returnsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(returnsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(controlsBar3, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab(org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.returnsPanel.TabConstraints.tabTitle"), returnsPanel); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.jLabel3.text")); // NOI18N

        balanceField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        balanceField.setText(org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.balanceField.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(saveButton, org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.saveButton.text")); // NOI18N
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(CreateEditSupplierDialog.class, "CreateEditSupplierDialog.cancelButton.text")); // NOI18N
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTabbedPane1)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(providerNameTextField)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jurPersonField)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(loadIPButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(saveButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cancelButton))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(balanceField, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(providerNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jurPersonField)
                    .addComponent(loadIPButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 35, Short.MAX_VALUE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTabbedPane1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(balanceField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(saveButton)
                    .addComponent(cancelButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void loadIPButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadIPButton1ActionPerformed
        if (null != jurPersonField.getText()
                && !jurPersonField.getText().isEmpty()) {
            List<JuridicalPerson> foundClient = JuridicalPersonDataProvider.getInstance().
                    getAllJuridicalPeronsByName(jurPersonField.getText());

            if (foundClient.isEmpty()) {
                UIUtils.showInfoMessage("Клиентов с заданными данными нет в базе");
            } else if (foundClient.size() == 1) {
                this.client = foundClient.get(0);
            } else {
                // Clients more than 1 - show table to choose correct one
                SearchJuridicPersonDialog dialog = new SearchJuridicPersonDialog(WindowManager.getDefault().getMainWindow(), true, foundClient);
                dialog.setLocationRelativeTo(null);
                dialog.setVisible(true);
                client = dialog.getClient();
            }

            if (null != client) {
                jurPersonField.setText(client.getName());
            }
        }
    }//GEN-LAST:event_loadIPButton1ActionPerformed

    private void addPaymentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addPaymentActionPerformed
        CreateEditPayment dialog = new CreateEditPayment(WindowManager.getDefault().getMainWindow(), true);
        dialog.setLocationRelativeTo(null);
        dialog.setMoneyTableModel(paymentsByClientsTableModel);
        dialog.setVisible(true);
        infoChanged();
    }//GEN-LAST:event_addPaymentActionPerformed

    private void editPaymentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editPaymentActionPerformed
        CreateEditPayment dialog = new CreateEditPayment(WindowManager.getDefault().getMainWindow(), true);
        dialog.setLocationRelativeTo(null);
        dialog.setMoneyTableModel(paymentsByClientsTableModel);
        dialog.setSupplierMoney(getPaymentFromClientSelection());
        dialog.setVisible(true);
        infoChanged();
    }//GEN-LAST:event_editPaymentActionPerformed

    private void deletePaymentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deletePaymentActionPerformed
        SupplierMoney delete = getPaymentFromClientSelection();
        SupplierDataProvider.getInstance().deleteSupplierMoney(delete.getId());
        paymentsByClientsTableModel.dataRemoved(delete);
        infoChanged();
    }//GEN-LAST:event_deletePaymentActionPerformed

    private void addPaymentForSupplierActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addPaymentForSupplierActionPerformed
        CreateEditPayment dialog = new CreateEditPayment(WindowManager.getDefault().getMainWindow(), true);
        dialog.setLocationRelativeTo(null);
        dialog.supplierMode();
        dialog.setMoneyTableModel(moneyForSupplierTableModel);
        dialog.setVisible(true);
        infoChanged();
    }//GEN-LAST:event_addPaymentForSupplierActionPerformed

    private void editPaymentForSupplierActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editPaymentForSupplierActionPerformed
        CreateEditPayment dialog = new CreateEditPayment(WindowManager.getDefault().getMainWindow(), true);
        dialog.setLocationRelativeTo(null);
        dialog.supplierMode();
        dialog.setMoneyTableModel(moneyForSupplierTableModel);
        dialog.setSupplierMoney(getPaymentForSupplierSelection());
        dialog.setVisible(true);
        infoChanged();
    }//GEN-LAST:event_editPaymentForSupplierActionPerformed

    private void deletePaymentForSupplierActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deletePaymentForSupplierActionPerformed
        SupplierMoney delete = getPaymentForSupplierSelection();
        SupplierDataProvider.getInstance().deleteSupplierMoney(delete.getId());
        moneyForSupplierTableModel.dataRemoved(delete);
        infoChanged();
    }//GEN-LAST:event_deletePaymentForSupplierActionPerformed

    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        if (null == client || providerNameTextField.getText().isEmpty() || balanceField.getText().isEmpty()) {
            UIUtils.showErrorMessage("Нужно указать наименование, выбрать юр.лицо и указать стартовый баланс");
            return;
        }
        boolean isCreate = false;
        if (null == supplier) {
            isCreate = true;
            supplier = new Supplier();
        }
        supplier.setName(providerNameTextField.getText());
        supplier.setJurClientId(client.getId());

        if (isCreate) {
            supplier.setStartBalance(Double.valueOf(balanceField.getText().replaceAll(",", ".")));
            supplier = SupplierDataProvider.getInstance().insertSupplier(supplier);
            supplierTableModel.dataAdded(supplier);
            for (SupplierMoney sm : paymentByClients) {
                sm.setType(0);
                sm.setSupplierId(supplier.getId());
                SupplierDataProvider.getInstance().insertSupplierMoney(sm);
            }
            for (SupplierMoney sm : moneyForSupplier) {
                sm.setType(1);
                sm.setSupplierId(supplier.getId());
                SupplierDataProvider.getInstance().insertSupplierMoney(sm);
            }
            for (SupplierMoney sm : paymentsByShop) {
                sm.setType(2);
                sm.setSupplierId(supplier.getId());
                SupplierDataProvider.getInstance().insertSupplierMoney(sm);
                createShopCost(sm);
            }
            for (Repayment sm : returnedPayments) {
                sm.setSupplierId(supplier.getId());
                SupplierDataProvider.getInstance().insertRepayment(sm);
            }
        } else {
            SupplierDataProvider.getInstance().updateSupplier(supplier);
            supplierTableModel.dataUpdated();
            for (SupplierMoney sm : paymentByClients) {
                if (sm.getId() != null) {
                    SupplierDataProvider.getInstance().updateSupplierMoney(sm);
                } else {
                    sm.setType(0);
                    sm.setSupplierId(supplier.getId());
                    SupplierDataProvider.getInstance().insertSupplierMoney(sm);
                }
            }
            for (SupplierMoney sm : moneyForSupplier) {
                if (sm.getId() != null) {
                    SupplierDataProvider.getInstance().updateSupplierMoney(sm);
                } else {
                    sm.setType(1);
                    sm.setSupplierId(supplier.getId());
                    SupplierDataProvider.getInstance().insertSupplierMoney(sm);
                }
            }
            for (SupplierMoney sm : paymentsByShop) {
                if (sm.getId() != null) {
                    SupplierDataProvider.getInstance().updateSupplierMoney(sm);
                } else {
                    sm.setType(2);
                    sm.setSupplierId(supplier.getId());
                    SupplierDataProvider.getInstance().insertSupplierMoney(sm);
                    createShopCost(sm);
                }
            }
            for (Repayment sm : returnedPayments) {
                if (sm.getId() != null) {
                    SupplierDataProvider.getInstance().updateRepayment(sm);
                } else {
                    sm.setSupplierId(supplier.getId());
                    SupplierDataProvider.getInstance().insertRepayment(sm);
                }
            }
        }
        setVisible(false);
    }//GEN-LAST:event_saveButtonActionPerformed

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        setVisible(false);
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void addPaymentByShopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addPaymentByShopActionPerformed
        CreateEditPayment dialog = new CreateEditPayment(WindowManager.getDefault().getMainWindow(), true);
        dialog.setLocationRelativeTo(null);
        dialog.paymentByShopMode();
        dialog.setMoneyTableModel(paymentsByShopTableModel);
        dialog.setVisible(true);
        infoChanged();
    }//GEN-LAST:event_addPaymentByShopActionPerformed

    private void editPaymentByShopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editPaymentByShopActionPerformed
        CreateEditPayment dialog = new CreateEditPayment(WindowManager.getDefault().getMainWindow(), true);
        dialog.setLocationRelativeTo(null);
        dialog.paymentByShopMode();
        dialog.setMoneyTableModel(paymentsByShopTableModel);
        dialog.setSupplierMoney(getPaymentByShopSelection());
        dialog.setVisible(true);
        infoChanged();
    }//GEN-LAST:event_editPaymentByShopActionPerformed

    private void deletePaymentByShopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deletePaymentByShopActionPerformed
        SupplierMoney delete = getPaymentByShopSelection();
        SupplierDataProvider.getInstance().deleteSupplierMoney(delete.getId());
        paymentsByShopTableModel.dataRemoved(delete);
        infoChanged();
    }//GEN-LAST:event_deletePaymentByShopActionPerformed

    private void addReturnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addReturnActionPerformed
        CreateEditRepaymentDialog dialog = new CreateEditRepaymentDialog(WindowManager.getDefault().getMainWindow(), true);
        dialog.setLocationRelativeTo(null);
        dialog.setRepaymentTableModel(returnedPaymentsTableModel);
        dialog.setVisible(true);
        infoChanged();
    }//GEN-LAST:event_addReturnActionPerformed

    private void editReturnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editReturnActionPerformed
        CreateEditRepaymentDialog dialog = new CreateEditRepaymentDialog(WindowManager.getDefault().getMainWindow(), true);
        dialog.setLocationRelativeTo(null);
        dialog.setRepaymentTableModel(returnedPaymentsTableModel);
        dialog.setRepayment(getReturnedPaymentSelection());
        dialog.setVisible(true);
        infoChanged();
    }//GEN-LAST:event_editReturnActionPerformed

    private void deleteReturnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteReturnActionPerformed
        Repayment delete = getReturnedPaymentSelection();
        SupplierDataProvider.getInstance().deleteRepayment(delete.getId());
        returnedPaymentsTableModel.dataRemoved(delete);
        infoChanged();
    }//GEN-LAST:event_deleteReturnActionPerformed

    public void setSupplier(Supplier supplier) {
        this.supplier = supplier;
        if (null != supplier) {
            balanceField.setEnabled(false);
            client = JuridicalPersonDataProvider.getInstance().selectJuridicalPersonByPrimaryKey(supplier.getJurClientId());
            providerNameTextField.setText(supplier.getName());
            jurPersonField.setText(client.getName());
            moneyForSupplier = SupplierDataProvider.getInstance().getPaymentsForSupplierBySupplierId(supplier.getId());
            paymentByClients = SupplierDataProvider.getInstance().getPaymentsFromClientBySupplierId(supplier.getId());
            paymentsByShop = SupplierDataProvider.getInstance().getPaymentsByShopBySupplierId(supplier.getId());
            returnedPayments = SupplierDataProvider.getInstance().getRepaymetsForSupplier(supplier.getId());
        } else {
            moneyForSupplier = new ArrayList<>();
            paymentByClients = new ArrayList<>();
            paymentsByShop = new ArrayList<>();
            returnedPayments = new ArrayList<>();
        }
        paymentsByClientsTableModel = new SupplierMoneyTableModel(paymentByClients);
        moneyForSupplierTableModel = new SupplierMoneyTableModel(moneyForSupplier);
        paymentsByShopTableModel = new SupplierMoneyTableModel(paymentsByShop);
        returnedPaymentsTableModel = new RepaymentTableModel(returnedPayments);
        paymentsByClientsTable.setModel(paymentsByClientsTableModel);
        paymentsByClientsTable.getColumnExt(0).setVisible(false);
        paymentsForSupplierTable.setModel(moneyForSupplierTableModel);
        paymentsByShopTable.setModel(paymentsByShopTableModel);
        paymentsByShopTable.getColumnExt(0).setVisible(false);
        returnedPaymentsTable.setModel(returnedPaymentsTableModel);
        returnedPaymentsTable.getColumnExt(0).setVisible(false);
        infoChanged();
    }

    protected SupplierMoney getPaymentFromClientSelection() {
        if (paymentsByClientsTable.getSelectedRow() > -1) {
            SupplierMoney orders = (SupplierMoney) paymentsByClientsTable
                    .getValueAt(paymentsByClientsTable.getSelectedRow(), -1);
            return orders;
        }
        return null;
    }

    protected SupplierMoney getPaymentForSupplierSelection() {
        if (paymentsForSupplierTable.getSelectedRow() > -1) {
            SupplierMoney orders = (SupplierMoney) paymentsForSupplierTable
                    .getValueAt(paymentsForSupplierTable.getSelectedRow(), -1);
            return orders;
        }
        return null;
    }

    protected SupplierMoney getPaymentByShopSelection() {
        if (paymentsByShopTable.getSelectedRow() > -1) {
            SupplierMoney orders = (SupplierMoney) paymentsByShopTable
                    .getValueAt(paymentsByShopTable.getSelectedRow(), -1);
            return orders;
        }
        return null;
    }

    protected Repayment getReturnedPaymentSelection() {
        if (returnedPaymentsTable.getSelectedRow() > -1) {
            Repayment orders = (Repayment) returnedPaymentsTable
                    .getValueAt(returnedPaymentsTable.getSelectedRow(), -1);
            return orders;
        }
        return null;
    }

    public SupplierTableModel getSupplierTableModel() {
        return supplierTableModel;
    }

    public void setSupplierTableModel(SupplierTableModel supplierTableModel) {
        this.supplierTableModel = supplierTableModel;
    }

    private void infoChanged() {
        Double moneyForSuppl = 0.0;
        Double payForProvider = 0.0;
        if (null != supplier) {
            payForProvider += supplier.getStartBalance();
        }
        for (SupplierMoney sm : moneyForSupplier) {
            moneyForSuppl += sm.getSumm();
        }
        for (SupplierMoney sm : paymentByClients) {
            payForProvider += sm.getSumm();
        }
        for (SupplierMoney sm : paymentsByShop) {
            payForProvider += sm.getSumm();
        }
        for (Repayment sm : returnedPayments) {
            payForProvider += sm.getSumma();
        }
        balanceField.setText("" + (payForProvider - moneyForSuppl));
    }

    public void createShopCost(SupplierMoney sm) {
        if (null != sm) {
            Cost cost = new Cost();
            cost.setDate(sm.getDate());
            cost.setSumma(sm.getSumm());
            cost.setCostTypeId(IdentifierConstants.PROVIDER_COST_TYPE_ID);
            cost.setPayMethod(sm.getPayMethod());
            CostDataProvider.getInstance().insertCost(cost);
        }
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addPayment;
    private javax.swing.JButton addPaymentByShop;
    private javax.swing.JButton addPaymentForSupplier;
    private javax.swing.JButton addReturn;
    private javax.swing.JTextField balanceField;
    private javax.swing.JButton cancelButton;
    private javax.swing.JToolBar controlsBar;
    private javax.swing.JToolBar controlsBar1;
    private javax.swing.JToolBar controlsBar2;
    private javax.swing.JToolBar controlsBar3;
    private javax.swing.JButton deletePayment;
    private javax.swing.JButton deletePaymentByShop;
    private javax.swing.JButton deletePaymentForSupplier;
    private javax.swing.JButton deleteReturn;
    private javax.swing.JButton editPayment;
    private javax.swing.JButton editPaymentByShop;
    private javax.swing.JButton editPaymentForSupplier;
    private javax.swing.JButton editReturn;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField jurPersonField;
    private javax.swing.JButton loadIPButton1;
    private javax.swing.JPanel paymentForSupplier;
    private javax.swing.JPanel paymentPanel;
    private org.jdesktop.swingx.JXTable paymentsByClientsTable;
    private javax.swing.JPanel paymentsByShopPanel;
    private org.jdesktop.swingx.JXTable paymentsByShopTable;
    private org.jdesktop.swingx.JXTable paymentsForSupplierTable;
    private javax.swing.JTextField providerNameTextField;
    private org.jdesktop.swingx.JXTable returnedPaymentsTable;
    private javax.swing.JPanel returnsPanel;
    private javax.swing.JButton saveButton;
    // End of variables declaration//GEN-END:variables
}
